export default {
  install(Vue) {
    Vue.prototype.api = {
      baseUrlV2: "/v2", //https://api.douguo.net
      baseUrlV3: "/v3", //https://passport.douguo.com
      baseUrlData: "/data", //https://apis.netstart.cn
      version: "7205.2",
      client: 4,
      msg:"在做了在做了",
      //关注用户
      payAttention(user, what = false) {
        let attentionList = JSON.parse(localStorage.getItem("attentionList")) || [];
        if(user?.user_id){
          attentionList = !what ? [user, ...attentionList.filter(item => item.user_id != user.user_id)] : attentionList.filter(item => item.user_id != user.user_id);
        }else{
          attentionList = !what ? [user, ...attentionList.filter(item => item.id != user.id||item.user_id != user.id)] : attentionList.filter(item => item.id != user.id);
        }
        localStorage.setItem("attentionList", JSON.stringify(attentionList));
      },
      //收藏菜谱
      payRecpie(recpie, what = false) {
        let recpieList = JSON.parse(localStorage.getItem("recpieList")) || [];
        recpieList = !what ? [recpie, ...recpieList.filter(item => item.r.id != recpie.r.id)] : recpieList.filter(item => item.r.id != recpie.r.id);
        localStorage.setItem("recpieList", JSON.stringify(recpieList));
      },
      //收藏课程
      payClass(classItem, what = false) {
        let classItemList = JSON.parse(localStorage.getItem("classItemList")) || [];
        classItemList = !what ? [classItem, ...classItemList.filter(item => item.id != classItem.id)] : classItemList.filter(item => item.id != classItem.id);
        localStorage.setItem("classItemList", JSON.stringify(classItemList));
      },
      //收藏笔记
      payNote(note, what = false) {
        let noteList = JSON.parse(localStorage.getItem("noteList")) || [];
        noteList = !what ? [note, ...noteList.filter(item => item.id != note.id)] : noteList.filter(item => item.id != note.id);
        localStorage.setItem("noteList", JSON.stringify(noteList));
      }
    }
  }
}